//加载当前日期
function loadDate() {
    var time = new Date();
    var myYear = time.getFullYear();
    var myMonth = time.getMonth() + 1;
    var myDay = time.getDate();
    if (myMonth < 10) {
        myMonth = "0" + myMonth;
    }
    document.getElementById("day_day").innerHTML = myYear + "." + myMonth + "." + myDay;
}

/**
 * 隐藏或者显示侧边栏
 *
 **/
function switchSysBar(flag) {
    var side = $('#side');
    var left_menu_cnt = $('#left_menu_cnt');
    if (flag == true) {	// flag==true
        left_menu_cnt.show(500, 'linear');
        side.css({width: '280px'});
        $('#top_nav').css({width: '77%', left: '304px'});
        $('#main').css({left: '280px'});
    } else {
        if (left_menu_cnt.is(":visible")) {
            left_menu_cnt.hide(10, 'linear');
            side.css({width: '60px'});
            $('#top_nav').css({width: '100%', left: '60px', 'padding-left': '28px'});
            $('#main').css({left: '60px'});
            $("#show_hide_btn").find('img').attr('src', 'images/common/nav_show.png');
        } else {
            left_menu_cnt.show(500, 'linear');
            side.css({width: '280px'});
            $('#top_nav').css({width: '77%', left: '304px', 'padding-left': '0px'});
            $('#main').css({left: '280px'});
            $("#show_hide_btn").find('img').attr('src', 'images/common/nav_hide.png');
        }
    }
}

$(function () {
    loadDate();

    // 显示隐藏侧边栏
    $("#show_hide_btn").click(function () {
        switchSysBar();
    });
});

//图标改变事件
$(function () {
    $("#TabPage2 li").click(function () {
        // alert("1444");

        //把所有的含有selected的样式的你都去掉
        $.each($("#TabPage2 li"), function (index, item) {
            $(item).removeClass("selected");
        })
        //给当前点击的li添加一个selected 样式
        $(this).addClass("selected");


        //把所有的图片的src属性改成不要_hover的值
        $.each($("#TabPage2 li"), function (index, item) {
            $(item).find("img").prop("src", "/images/common/" + ($(this).index() + 1) + ".jpg");
        })
        //2给当前点击的li里面的img设置src属性
        $(this).find("img").prop("src", "/images/common/" + ($(this).index() + 1) + "_hover.jpg");

        //3修改菜单栏的图片显示
        $("#nav_module img").prop("src", "/images/common/module_" + ($(this).index() + 1) + ".png");
        //4显示对应的系统菜单
        loadMenu($(this).data("rootmenu"));

    })
})


var setting = {
    data: {
        simpleData: {
            enable: true
        }
    },

    async: {
        enable: true,
        url: "/systemMenu/queryMenusByParentSn.do",
        autoParam: ["id=parentId"]
    },

    callback: {
        onClick: function (event, treeId, treeNode) {
            if (treeNode.action) {
                //打开系统菜单的页面
                $("#rightMain").prop("src", treeNode.action+".do");
                $("#here_area").html("当前位置:" + treeNode.getParentNode().name + ">" + treeNode.name);
            }
        }

    }


};

var treeNodes = {
    "business": [
        {id: 2, pId: 0, name: "业务模块", open: false, isParent: true},
    ],
    "systemManage": [

        {id: 1, pId: 0, name: "系统模块", open: false, isParent: true},

    ],
    "charts": [
        {id: 3, pId: 0, name: "报表模块", open: false, isParent: true}, /*是否有父节点*/
    ]
};

//根据编码加载对应的菜单

function loadMenu(sn) {
    $.fn.zTree.init($("#dleft_tab1"), setting, treeNodes[sn]);
}

$(function () {
    loadMenu("business");
})



